home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / src / WBBump_src.lha / WBBump_src / pluginmanager.e < prev    next >
Encoding:
Text File  |  1999-06-30  |  8.6 KB  |  435 lines

  1. /* *************** */
  2. /* pluginmanager.e */
  3. /* *************** */
  4.  
  5.  
  6.  
  7. /*
  8.     WBBump - Bumpmapping on the Workbench!
  9.  
  10.     Copyright (C) 1999  Thomas Jensen - dm98411@edb.tietgen.dk
  11.  
  12.     This program is free software; you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation; either version 2 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software Foundation,
  24.     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. */
  26.  
  27.  
  28. OPT MODULE
  29.  
  30.  
  31. MODULE    'exec/nodes',
  32.         'exec/lists',
  33.  
  34.         'utility/tagitem',
  35.  
  36.         'dos/dos',
  37.  
  38.         'amigalib/lists'
  39.  
  40.  
  41. MODULE    '*plugin',
  42.         '*plugin_const',
  43.         '*errors'
  44.  
  45.  
  46.  
  47. OBJECT pluginnode OF ln
  48. PRIVATE
  49.     theplugin    :    PTR TO plugin
  50. ENDOBJECT
  51.  
  52.  
  53. EXPORT OBJECT pluginlist
  54. PRIVATE
  55.     list    :    lh
  56.     current    :    PTR TO pluginnode
  57. ENDOBJECT
  58.  
  59.  
  60.  
  61.  
  62. /*******************************************************************************
  63.     constructor
  64. *******************************************************************************/
  65.  
  66. PROC pluginlist() OF pluginlist HANDLE
  67.  
  68.     /* init list header */
  69.     newList(self.list)
  70.  
  71.     self.moveFirst()
  72.  
  73. EXCEPT DO
  74.     ReThrow()
  75. ENDPROC
  76.  
  77.  
  78. /*******************************************************************************
  79.     load all plugins
  80. *******************************************************************************/
  81.  
  82. PROC loadall() OF pluginlist HANDLE
  83.  
  84.     self.loaddir('PROGDIR:Plugins/')
  85.  
  86. EXCEPT DO
  87.     ReThrow()
  88. ENDPROC
  89.  
  90.  
  91.  
  92. /******************************************************************************
  93.     load a complete directory of plugins
  94. ******************************************************************************/
  95.  
  96. PROC loaddir(dirname) OF pluginlist HANDLE
  97.     DEF    dirlock=NIL,
  98.         olddirlock=-1,
  99.         match=NIL,
  100.         fib=NIL:PTR TO fileinfoblock
  101.  
  102.  
  103.     NEW fib
  104.  
  105.     match := NewR(100)
  106.  
  107.     ParsePatternNoCase('#?.wbbplugin', match, 100)
  108.  
  109.     IF (dirlock := Lock(dirname, ACCESS_READ)) = NIL THEN Raise(-1)
  110.     olddirlock := CurrentDir(dirlock)
  111.  
  112.     IF Examine(dirlock, fib) = 0 THEN Raise(-1)
  113.  
  114.     IF fib.direntrytype < 0 THEN Raise(-1)
  115.  
  116.     WHILE (ExNext(dirlock, fib) <> FALSE)
  117.  
  118.         IF MatchPatternNoCase(match, fib.filename)
  119.  
  120.             self.addFile(fib.filename)
  121.  
  122.         ENDIF
  123.  
  124.     ENDWHILE
  125.  
  126. EXCEPT DO
  127.     IF olddirlock <> -1 THEN CurrentDir(olddirlock)
  128.     IF dirlock THEN UnLock(dirlock)
  129.     END fib
  130.     IF exception THEN RETURN FALSE
  131. ENDPROC TRUE
  132.  
  133.  
  134.  
  135.  
  136. /******************************************************************************
  137.     add a plugin and add it to list
  138. ******************************************************************************/
  139.  
  140. PROC addFile(filename) OF pluginlist HANDLE
  141.     DEF    pl=NIL:PTR TO plugin
  142.  
  143.     NEW pl.plugin()
  144.  
  145.     IF pl.load(filename)
  146.         self.addPlugin(pl)
  147.     ELSE
  148.         END pl
  149.     ENDIF
  150.  
  151. EXCEPT DO
  152.     IF exception THEN RETURN FALSE
  153. ENDPROC TRUE
  154.  
  155.  
  156.  
  157. /******************************************************************************
  158.     add an initialised plugin to list
  159. ******************************************************************************/
  160.  
  161. PROC addPlugin(pl:PTR TO plugin) OF pluginlist HANDLE
  162.     DEF    pn=NIL:PTR TO pluginnode
  163.  
  164.     NEW pn
  165.     pn.name := String(StrLen(pl.getName())+1)
  166.     StrCopy(pn.name, pl.getName())
  167.     pn.theplugin := pl
  168.  
  169.     AddTail(self.list, pn)
  170.  
  171. EXCEPT DO
  172.     IF exception THEN RETURN FALSE
  173. ENDPROC TRUE
  174.  
  175.  
  176. /******************************************************************************
  177.     move to the first element in list
  178. ******************************************************************************/
  179.  
  180. PROC moveFirst() OF pluginlist
  181.     IF self.isEmpty()
  182.         self.current := NIL
  183.         RETURN FALSE
  184.     ELSE
  185.         self.current := self.list.head
  186.     ENDIF
  187. ENDPROC TRUE
  188.  
  189.  
  190. /******************************************************************************
  191.     move to the next element in the list
  192. ******************************************************************************/
  193.  
  194. PROC moveNext() OF pluginlist
  195.     IF self.current.succ.succ
  196.         self.current := self.current.succ
  197.     ELSE
  198.         self.current := NIL
  199.         RETURN FALSE
  200.     ENDIF
  201. ENDPROC TRUE
  202.  
  203.  
  204. /******************************************************************************
  205.     return a pointer to the current plugin
  206. ******************************************************************************/
  207.  
  208. PROC getCurrent() OF pluginlist
  209.     IF self.current THEN RETURN self.current.theplugin
  210. ENDPROC NIL
  211.  
  212.  
  213.  
  214. /******************************************************************************
  215.     is the list empty?
  216. ******************************************************************************/
  217.  
  218. PROC isEmpty() OF pluginlist IS (self.list.head.succ = NIL)
  219.  
  220.  
  221. /******************************************************************************
  222.     remove the current element in list
  223. ******************************************************************************/
  224.  
  225. PROC removeCurrent() OF pluginlist
  226.     DEF    pn=NIL:PTR TO pluginnode
  227.  
  228.     IF self.current
  229.         pn := self.current
  230.         self.moveNext()
  231. ->        WriteF('Removing from list : \s :\s\n', IF pn.theplugin.isClass() THEN 'Class' ELSE 'Instance', pn.theplugin.getName())
  232.         END pn.theplugin
  233.         Remove(pn)
  234.     ELSE
  235.         RETURN FALSE
  236.     ENDIF
  237. ENDPROC TRUE
  238.  
  239.  
  240.  
  241.  
  242.  
  243. /******************************************************************************
  244.     add a list of instances matching tooltypes found in masterlist
  245. ******************************************************************************/
  246.  
  247. PROC addInstancesTT(tt:PTR TO LONG, masterlist:PTR TO pluginlist, warn=TRUE) OF pluginlist HANDLE
  248.     DEF    pl=NIL:PTR TO plugin,
  249.         newpl=NIL:PTR TO plugin,
  250.         strlen,
  251.         cursizex=-1, cursizey=-1,
  252.         curstr,
  253.         args=-1,
  254.         i=0
  255.  
  256.  
  257.     i := 0
  258.     WHILE (tt[i] <> 0)
  259.         curstr := tt[i]
  260.         IF masterlist.moveFirst()
  261.  
  262.             REPEAT
  263.  
  264.                 IF (pl := masterlist.getCurrent())
  265.  
  266.                     strlen := StrLen(pl.getCommandName())
  267.  
  268.                     IF StrCmp(curstr, pl.getCommandName(), strlen)
  269.  
  270.                         args := -1
  271.  
  272.                         IF (curstr[strlen] = "=")
  273.                             args := curstr+strlen+1
  274.                         ELSEIF (curstr[strlen] = 0)
  275.                             args := NIL
  276.                         ENDIF
  277.  
  278.                         IF args <> -1
  279.  
  280.                             IF (newpl := pl.createInstance([
  281.  
  282.                                 PLUGINTAG_ARGS, args,
  283.                                 PLUGINTAG_WIDTH, cursizex,
  284.                                 PLUGINTAG_HEIGHT, cursizey,
  285.                                 TAG_END]))
  286.  
  287.                                 cursizex := newpl.getWidth()
  288.                                 cursizey := newpl.getHeight()
  289.  
  290.                                 self.addPlugin(newpl)
  291.  
  292. ->                                WriteF('***New instance added***\n')
  293. ->                                newpl.writeinfo()
  294.  
  295.  
  296.                             ELSE
  297.                                 IF warn THEN showWarning('WBBump warning', 'Ok', 'CreateInstance failed for "\s"\n  args: "\s"\n  Error was: "\s"\n', [pl.getName(), args, pl.getLastError()])
  298.                             ENDIF
  299.  
  300.                         ENDIF
  301.  
  302.                     ENDIF
  303.  
  304.                 ENDIF
  305.  
  306.             UNTIL (masterlist.moveNext() = FALSE)
  307.  
  308.         ENDIF
  309.         i++
  310.     ENDWHILE
  311.  
  312.  
  313. EXCEPT DO
  314.     IF exception
  315.         RETURN FALSE
  316.     ENDIF
  317. ENDPROC TRUE
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324. /******************************************************************************
  325.     find sizes of first plugin
  326. ******************************************************************************/
  327.  
  328. PROC getFirstWidth() OF pluginlist
  329.     DEF    pl=NIL:PTR TO plugin
  330.  
  331.     IF self.moveFirst()
  332.         IF (pl := self.getCurrent())
  333.             RETURN pl.getWidth()
  334.         ENDIF
  335.     ENDIF
  336. ENDPROC -1
  337.  
  338.  
  339.  
  340. PROC getFirstHeight() OF pluginlist
  341.     DEF    pl=NIL:PTR TO plugin
  342.  
  343.     IF self.moveFirst()
  344.         IF (pl := self.getCurrent())
  345.             RETURN pl.getHeight()
  346.         ENDIF
  347.     ENDIF
  348. ENDPROC -1
  349.  
  350.  
  351.  
  352.  
  353.  
  354. /******************************************************************************
  355.     returns TRUE if ANY plugin needs update
  356. ******************************************************************************/
  357.  
  358. PROC needUpdate() OF pluginlist
  359.     DEF    pl=NIL:PTR TO plugin
  360.  
  361.     IF self.moveFirst()
  362.         WHILE (pl := self.getCurrent())
  363.             IF pl.needUpdate() THEN RETURN TRUE
  364.             self.moveNext()
  365.         ENDWHILE
  366.     ENDIF
  367.  
  368. ENDPROC FALSE
  369.  
  370.  
  371.  
  372.  
  373.  
  374. /******************************************************************************
  375.     execute plugins, if needed
  376. ******************************************************************************/
  377.  
  378. PROC doUpdate() OF pluginlist HANDLE
  379.     DEF    pl=NIL:PTR TO plugin,
  380.         updating=FALSE,
  381.         finalbuf=NIL,
  382.         lastbuf=0
  383.  
  384.  
  385.     IF self.moveFirst()
  386.         WHILE (pl := self.getCurrent())
  387.  
  388.             IF pl.getType() = PLUGINTYPE_BUMPER
  389.  
  390.                 IF pl.needUpdate() THEN updating := TRUE
  391.  
  392.                 IF updating
  393.                     pl.doAction(lastbuf)
  394.                     lastbuf := pl.getOutBuf()
  395.                 ENDIF
  396.  
  397.                 finalbuf := pl.getOutBuf()
  398.  
  399.             ENDIF
  400.  
  401.             self.moveNext()
  402.  
  403.         ENDWHILE
  404.     ENDIF
  405.  
  406. EXCEPT DO
  407.     IF exception THEN RETURN NIL
  408. ENDPROC finalbuf
  409.  
  410.  
  411.  
  412.  
  413.  
  414. /******************************************************************************
  415.     destructor
  416. ******************************************************************************/
  417.  
  418. PROC end() OF pluginlist
  419.  
  420.     IF self.moveFirst()
  421.         REPEAT
  422.             self.removeCurrent()
  423.             self.moveFirst()
  424.         UNTIL (self.isEmpty() = TRUE)
  425.     ENDIF
  426. ENDPROC
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.